package o2o.web.actions.shop;

import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 *
 * @Desc: 店铺类型处理模块  主要为了店铺类型的横向扩展
 * @User: @Created by yangtk
 * @Date: @Date 2019/10/23 10:21
 * @Classname: ShopCategoryMan
 * @To change this template use File | Settings | File Templates.
 */
public class ShopCategoryMan {


    public static Integer shopTypeShopping = 1 << 0; // 外卖 1 0001
    public static Integer shopTypeGroup = 1 << 1; // 团购 2 0010
    //    public static Integer shopTypeExample = 1 << 2; // 举例 4 0100
    private static Set<Integer> dataSet = new HashSet<>();

    static {
        dataSet.add(shopTypeShopping);
        dataSet.add(shopTypeGroup);
//        dataSet.add(shopTypeExample);
    }

    /**
     * @param shopType 店铺类型
     * @return
     * @desc 是否是当前系统的类型
     */
    public static boolean hasShopType(Integer shopType) {
        if (shopType == null) {
            return false;
        }
        return dataSet.contains(shopType);
    }

    /**
     * @param ruleShopType
     * @param shopType
     * @return
     * @Desc 是否是哪种类型店铺
     */
    public static boolean validShopType(int ruleShopType, Integer shopType) {
        if (shopType == null) {
            return false;
        }
        return (ruleShopType & shopType) > 0;
    }

    /**
     * @param shopType
     * @return
     * @desc 检测是不是团购店铺
     */
    public static boolean validGroupShopType(Integer shopType) {
        return validShopType(shopTypeGroup, shopType);
    }



    /**
     * @param originShopType 当前的类型
     * @param shopType       有赋予的类型
     * @return
     * @desc 给商家赋予某种类型
     */
    public static int assignmentShopType(Integer originShopType, int shopType) {
        if (originShopType == null) {
            originShopType = 0;
        }
        return originShopType | shopType;
    }

    /**
     * @param originShopType
     * @return
     * @desc 授予团购类型
     */
    public static int assignmentGroupShopType(Integer originShopType) {
        if (originShopType == null) {
            originShopType = 0;
        }
        return assignmentShopType(originShopType, shopTypeGroup);
    }

}
